<?php
error_reporting(0);
class ProductInfo{
    function ProductInfo2(){

        //提现类型D0orD1
        $WITHDRAWMAP = $_REQUEST["WITHDRAWMAP"];
        //提现产品费率名称（工作日 or 非工作日）
        $d0withdrawBankName = $_REQUEST["D0withdrawBankName"];
        $d1withdrawBankName = $_REQUEST["D1withdrawBankName"];

        $d0fixedRate = $_REQUEST["D0fixedRate"];
        $d1fixedRate = $_REQUEST["D1fixedRate"];
        $d0percentRate = $_REQUEST["D0percentRate"];
        $d1percentRate = $_REQUEST["D1percentRate"];


        $withDrawjson = ProductInfo::CreateWithDrawJson($WITHDRAWMAP, $d0withdrawBankName, $d1withdrawBankName);
        echo '生成的信息如下:';
      
		echo json_encode($withDrawjson);

    }

    function CreateWithDrawJson($WITHDRAWMAP, $d0withdrawBankName, $d1withdrawBankName) {
        if (count($WITHDRAWMAP) <= 0) {
        return "";
        }

        $d0Map = "";
        if ($d0withdrawBankName != null && count($d0withdrawBankName) > 0) {
            foreach ($d0withdrawBankName as $d0BankName) {
                if ($d0BankName=="WITHDRAW_WORKDAY") {
                    $d0Map_1 = ProductInfo::createOne("MIXED", $_REQUEST["D0fixedRate_work"], $_REQUEST["D0percentRate_work"]);
                    $d0Map = array(WITHDRAW_WORKDAY=>$d0Map_1);
                }

                if ($d0BankName=="WITHDRAW_WEEKDAY") {
                    $d0Map_2 = ProductInfo::createOne("MIXED", $_REQUEST["D0fixedRate_week"], $_REQUEST["D0percentRate_week"]);
                    if($d0Map=="")
                        $d0Map = array(WITHDRAW_WEEKDAY=>$d0Map_2);
                    else
                        $d0Map = array_merge($d0Map,array(WITHDRAW_WEEKDAY=>$d0Map_2));
                }
            }
        }


        $d1Map = "";
        if ($d1withdrawBankName != null && count($d1withdrawBankName) > 0) {
            foreach ($d1withdrawBankName as $d1BankName) {
                if ($d1BankName == "WITHDRAW_WORKDAY") {
                    $d1Map_1 = ProductInfo::createOne("MIXED", $_REQUEST["D1fixedRate_work"], $_REQUEST["D1percentRate_work"]);
//                    $d1Map = array(WITHDRAW_WORKDAY=>$map);
                    echo "123";
                    $d1Map = array(WITHDRAW_WORKDAY=>$d1Map_1);
                }

                if ($d1BankName == "WITHDRAW_WEEKDAY") {
                    $d1Map_2 = ProductInfo::createOne("MIXED", $_REQUEST["D1fixedRate_week"], $_REQUEST["D1percentRate_week"]);
//                    $d1Map_2 = array(WITHDRAW_WEEKDAY=>$map);
                    if($d1Map=="")
                        $d1Map = array(WITHDRAW_WEEKDAY=>$d1Map_2);
                    else
                        $d1Map = array_merge($d1Map,array(WITHDRAW_WEEKDAY=>$d1Map_2));
                }
            }
        }

        $d0ParentMap = array(dsWithdrawBankMap=>$d0Map);

        $d1ParentMap = array(dsWithdrawBankMap=>$d1Map);


        $d0PParentMap = array(WITHDRAW_D0=>$d0ParentMap);

        $d1PParentMap = array(WITHDRAW_D1=>$d1ParentMap);


        $map = array(
            WITHDRAW_D0=>$d0ParentMap,
            WITHDRAW_D1=>$d1ParentMap);

        return $map;
    }
    function createOne($rateType, $fixedRate, $percentRate) {
        $map = array(rateType=>$rateType,
         fixedRate=>$fixedRate,
         percentRate=>$percentRate);

        return $map;
    }
}
ProductInfo::ProductInfo2();